package com.antong.cloud.order.provider.controller;


import com.antong.cloud.order.provider.entity.Booking;
import com.antong.cloud.order.provider.service.IBookingService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tzq
 * @since 2022-09-25
 */
@RestController
@RequestMapping("/booking")
public class BookingController {

    @Autowired
    IBookingService bookingService;

    @GetMapping("getBookingById")
    private Booking getBookingById(String bookingId){
        QueryWrapper<Booking> wrapper = new QueryWrapper();
        wrapper.eq("fid", "+++U0PqGQ6CpAeVGh3TGV9H5lcM=");
        return bookingService.getOne(wrapper);
    }

    @GetMapping("listBooking")
    private Page<Booking> listBooking(String bookingId){
        SecurityContextHolder.getContext().getAuthentication();
        Wrappers.<Booking>lambdaQuery().eq(bookingId != null, Booking::getFid, bookingId);
        QueryWrapper<Booking> wrapper = new QueryWrapper();
        wrapper.eq("fid", "+++U0PqGQ6CpAeVGh3TGV9H5lcM=");
        Page<Booking> page = new Page<>(1, 10);
        bookingService.page(page, wrapper);
        return page;
    }

    @PostMapping("testForm")
    private void testForm(String username){
        System.out.printf(username);
    }

}
